/**
 * Copyright (C), 2001-2023, www.bosssof.com.cn
 * FileName: UserApi
 * Author: Administrator
 * Date: 2023-03-30 16:00:07
 * Description:
 * <p>
 * History:
 * <author> Administrator
 * <time> 2023-03-30 16:00:07
 * <version> 1.0.0
 * <desc> 版本描述
 */
package com.bosssoft.quickstart.demo.api;

import com.bosssoft.quickstart.demo.pojo.dto.IdVersion;
import com.bosssoft.quickstart.demo.pojo.dto.UserDTO;
import com.bosssoft.quickstart.demo.pojo.query.UserQuery;
import com.bosssoft.quickstart.demo.pojo.vo.CommonPage;
import com.bosssoft.quickstart.demo.pojo.vo.CommonResponse;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @ClassName: UserApi
 * @Description: 有用配合前端演示用户增删改查的demo
 * @Author: Administrator
 * @Date: 2023-03-30 16:00
 **/
@CrossOrigin
@Api(tags = "用户管理 ", value = "/quickstart/demo/v1/user")
@RequestMapping("/quickstart/demo/v1")
@Validated
public interface UserApi {
    /**
     *  界面调用接口增加用户
     * @param userDTO 用户信息
     * @return true成功 false失败
     */
    @ApiOperation( value = "增加用户",notes="界面增加用户")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "请求执行没有成功但是发生异常")
            }
    )
    @PostMapping("/user")
    CommonResponse<Boolean> add(@NotNull @Valid @RequestBody @ApiParam(value = "用户数据", required = true) UserDTO userDTO);
    /**
     *  删除用户
     * @param id  记录id
     * @return  true 成功 false失败
     */
    @ApiOperation(value = "删除用户通过id",notes = "通过id删除用户")
    @ApiImplicitParam(name = "id",required =true,dataType = "Long",paramType = "path")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    }
    )
    @DeleteMapping("/user")
    CommonResponse<Boolean> remove(@PathVariable @NotNull Long id);

    /**
     *  通过id和version比较删除用户
     * @param id  记录id
     * @param version 版本
     * @return  true 成功 false失败
     */
    @ApiOperation(value = "删除用户通过id和版本",response = Boolean.class,notes = "notes说明")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",required =true,dataType = "Long",paramType = "query"),
            @ApiImplicitParam(name = "version",required =true,dataType = "Long",paramType = "query")}
    )
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    }
    )
    @DeleteMapping("/optimism/user")
    CommonResponse<Boolean> remove(@NotNull @RequestParam("id") Long id,@NotNull @RequestParam("version") Long version);

    /**
     * 批量删除用户
     * @param idVersions
     * @return
     */
    @ApiOperation(value = "批量删除用户通过id和版本",response = Boolean.class,notes = "notes说明")
    @ApiImplicitParams({@ApiImplicitParam(name = "idVersions",required =true,dataType = "IdVersion",paramType = "body")}
    )
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    }
    )
    @DeleteMapping("/batch/user")
    CommonResponse<Boolean> remove(@NotEmpty @RequestBody  IdVersion[] idVersions);


    /**
     * 界面调用接口更新用户信息
     * @param userDTO 用户信息包含 id
     * @return true成功 false失败
     */
    @ApiOperation( value = "更新用户信息",notes = "修改界面保存调用该方法")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    }
    )
    @PutMapping("/user")
    CommonResponse<Boolean> update(@NotNull @Valid @RequestBody  @ApiParam UserDTO userDTO);

    /**
     * 界面调用接口更新用户信息
     * @param userQuery 用户信息包含 id
     * @return true成功 false失败
     */
    @ApiOperation(value = "查询用户列表接口",notes = "支持模糊查询")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功"),
            @ApiResponse(code=-1,message = "没有更新记录,非0码则代表失败")
    })
    @GetMapping("/user")
    CommonResponse<CommonPage<UserDTO>> search(@NotNull @Valid @RequestBody UserQuery userQuery);

    /**
     *  页面编辑行的时候传id从后端加载数据
     * @param id  当前行id
     * @return  用户数据
     */
    @ApiOperation(value = "根据id获取用户接口",notes = "用于编辑和查看的时候获取用户")
    @ApiImplicitParam(name = "id",value = "主键值",required = true,dataType = "Long",paramType = "path")
    @ApiResponses({
            @ApiResponse(code = 0,message = "请求成功,非0码则代表失败"),
    })
    @GetMapping("/user/{id}")
    CommonResponse<UserDTO> findById( @PathVariable @NotNull Long id);

}
